package com.qf.data.user.vaild;

import com.qf.commons.standar.vaild.IQfValid;
import com.qf.commons.standar.vaild.QfVaild;
import com.qf.data.user.vo.input.RedEnveInput;
import org.springframework.stereotype.Component;

/**
 * description:
 * author: Ken
 * 公众号：Java架构栈
 */
@Component
public class RedParamsVaild implements IQfValid {

    @Override
    public boolean vaild(QfVaild qfVaild, Object object) {

        RedEnveInput redEnveInput = (RedEnveInput) object;
        //做相关的关联校验
        if (redEnveInput.getScore() == null || redEnveInput.getCount() == null || redEnveInput.getType() == null)
            return true;

        //判断积分额度 必须 大于份数
        if (redEnveInput.getScore() < redEnveInput.getCount()) {
            return false;
        }

        //如果是固定红包，积分额度必须 整除 份数
        if (redEnveInput.getType() == 0) {
            return redEnveInput.getScore() % redEnveInput.getCount() == 0;
        }
        return true;
    }
}
